/*
 * @Author: LiJia
 * @Date: 2021-03-10 13:07:39
 * @LastEditTime: 2021-04-01 05:00:33
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \class-manage-system\miniprogram\pages\mine\children\my-homework\my-homework.ts
 */
Page({

  // 页面的初始数据
  data: {
    homeworkTable: [],
    total: 0,
    hasMoreHomeworkInfo: false,
    clsUserInfo: {}
  },

  // 生命周期函数--监听页面加载
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('clsUserInfo', (req) => {
      this.setData({
        clsUserInfo: req.data
      })
    })
    this.getHomeworkTable()
  },

  // 生命周期函数--监听页面初次渲染完成
  onReady() {},

  // 生命周期函数--监听页面显示
  onShow() {},

  // 生命周期函数--监听页面隐藏
  onHide() {},

  // 生命周期函数--监听页面卸载
  onUnload() {},

  // 页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh() {},

  // 页面上拉触底事件的处理函数
  onReachBottom() {},

  // 用户点击右上角分享
  onShareAppMessage() {
    return {};
  },

  getHomeworkTable() {
    const apiUrl = wx.getStorageSync('apiUrl')
    let that = this
    wx.request({
      url: apiUrl + '/homework',
      data: {
        id: (this.data.clsUserInfo as any).id || "",
        role: (this.data.clsUserInfo as any).role || ""
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let _res = res.data as any
        if (_res.code === 200) {
          // _res.data = JSON.parse(_res.data)
          that.setData({
            homeworkTable: _res.data,
            total: 0
          })
        } else {
          wx.showToast({
            title: _res.msg,
            icon: 'none',
            duration: 2021
          })
        }
      }
    })
  }
})
